package com.lyf.aop.sguigu.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

/**
 * @AUTHOR LYF
 * @DATE 2022/5/15
 * @VERSION 1.0
 * @DESC
 */
//@EnableAspectJAutoProxy
@Component
@Aspect
public class ControllerAspect {
    Long startTime;
    Long endTime;
    //String pointCut = "public String com.lyf.aop.sguigu.controller.LoginController.";
    @Before(
            value = "execution(public String com.lyf.aop.sguigu.controller.LoginController.login(String,String)) && args(name,password)",
            argNames = "name,password")
    public void startLogin(String name,String password){
        startTime = System.currentTimeMillis();
        System.out.println("传入参数:"+name+password);
        System.out.println("startLogin");
    }
    @AfterReturning("execution(public String com.lyf.aop.sguigu.controller.LoginController.login(String,String))")
    public void afterReturn(){
        endTime = System.currentTimeMillis();
        System.out.println("afterReturn:");
    }
    @After("execution(public String com.lyf.aop.sguigu.controller.LoginController.login(String,String))")
    public void endLogin(){//String name,String password

        System.out.println("ending:"+startTime+":"+endTime+":"+(endTime-startTime));
        System.out.println("endLogin");
    }

    @AfterThrowing("execution(public String com.lyf.aop.sguigu.controller.LoginController.login(String,String))")
    public void afterThrowing(){
       // System.out.println("execption");
    }

//    @Around("execution(public String com.lyf.aop.sguigu.controller.LoginController.login(String,String))")
//    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
//        proceedingJoinPoint.proceed();
//       // return "更改--";
//    }

}
